<template>
  <PageTemplate rowKey="affairId"
                :tableRequest="tableRequest"
                :metaDataRequestParams="metaDataRequestParams"
                :toolButtonList="toolButtonList"
                :isShowTableCheckbox="false"
                @onMetaDataChange="handleMetaDataChange"
                @onToolClick="handleToolClick"
                @onRowClick="handleRowClick">
  </PageTemplate>
</template>
<script>
  import PageTemplate from '@/components/page-template';
  import mixin from './mixin';
  import collaboration from '@/utils/collaboration.js';
  import smartCodeMixin from '@/mixins/smart-code-mixin.js';
  import { getParams } from '@/utils';

  const urlParamObj = getParams(window.location.search);
  export default {
    name: 'PageMyDownList',
    mixins: [mixin, smartCodeMixin],
    components: { PageTemplate },
    data() {
      return {
        tableRequest: {
          url: '/ajax.do?method=ajaxAction&managerName=handoverManager',
          managerMethod: 'listAffairs',
          otherArgs: { state: '4', type: 'toMe', templeteIds: urlParamObj.textfield || '' }
        },
        metaDataRequestParams: {
          key: 'LIST_DONE_HANDOVER_TO_ME',
          platform: 0
        },
        toolButtonList: []
      };
    },
    methods: {
      // 智码扫码成功后，智码预处理时，获取解码参数
      getSmartCodeDecodeParam(data) {
        const obj = this.searchConditionsValue;
        obj.openFrom = 'listDone';
        return obj;
      },
      // 智码扫码成功后回调
      smartCodeCallBack(data) {
        collaboration.smartCodeCallBack(data);
      },
      handleToolClick(buttonId, { selectedRows, searchConditionsValue }, resetTableData) {
        switch (buttonId) {
          case 'smartCodeScan':
            this.searchConditionsValue = searchConditionsValue;
            this.showSmartCode && this.showSmartCode();
            break;
        }
      },
      handleMetaDataChange({ globalParam }) {
        const needButtonList = [];
        this.supportSmartCode = globalParam ? globalParam.supportSmartCode : undefined;
        let smartCodeIndex = 0;
        if (!this.isHaveSmartCodePermission()) {
          // 没有扫一扫权限
          smartCodeIndex = undefined;
        }
        this.initToolButtonList(needButtonList, globalParam, smartCodeIndex);
      }
    }
  };
</script>
